<?php

use Faker\Factory as Faker;
use App\Models\ChannelUserItem;
use App\Repositories\ChannelUserItemRepository;

trait MakeChannelUserItemTrait
{
    /**
     * Create fake instance of ChannelUserItem and save it in database
     *
     * @param array $channelUserItemFields
     * @return ChannelUserItem
     */
    public function makeChannelUserItem($channelUserItemFields = [])
    {
        /** @var ChannelUserItemRepository $channelUserItemRepo */
        $channelUserItemRepo = App::make(ChannelUserItemRepository::class);
        $theme = $this->fakeChannelUserItemData($channelUserItemFields);
        return $channelUserItemRepo->create($theme);
    }

    /**
     * Get fake instance of ChannelUserItem
     *
     * @param array $channelUserItemFields
     * @return ChannelUserItem
     */
    public function fakeChannelUserItem($channelUserItemFields = [])
    {
        return new ChannelUserItem($this->fakeChannelUserItemData($channelUserItemFields));
    }

    /**
     * Get fake data of ChannelUserItem
     *
     * @param array $postFields
     * @return array
     */
    public function fakeChannelUserItemData($channelUserItemFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'channel_id' => $fake->randomDigitNotNull,
            'wechat_user_id' => $fake->randomDigitNotNull,
            'item_id' => $fake->randomDigitNotNull,
            'status' => $fake->randomDigitNotNull,
            'updated_at' => $fake->word,
            'created_at' => $fake->word
        ], $channelUserItemFields);
    }
}
